<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%-- <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> --%>
<%-- <base href="<%=basePath%>" /> --%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>注册页面</title>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<%-- <script type="text/javascript" src="${basepath }js/jquery.min.js"></script> --%>
<style type="text/css">
table,tr,td{
		text-align: center;
		}
	td{
		width: 80px;
		}
	tr{
		height: 60px
		}
	.bottom{border:none;background:url  left top no-repeat;width:120px; height:30px; background-color: #3F90F3}	
</style>
</head>
<body>
	<%--${pageContext.request.contextPath}  打印出来是百度--%>	
<center>
	<img src="${pageContext.request.contextPath}/images/baidu2.png">
		<form action="insert" method="post" id="form1">
		<table>
			<tr>
				<td>用户名：</td>
				<td>
					<input type="text" name="uname" id="uname" onblur="checkName()">
				</td>
				<td style="width: 200px"><font class="fot1"></font></td>
			</tr>
			<tr>
				<td>公司名称：</td>
				<td>
					<input type="text" name="companyname" id="companyname" onblur="checkCompanyName()"/>
				</td>
				<td style="width: 200px"><font class="fot2"></font></td>
			</tr>
			<tr>
				<td>公司税号：</td>
				<td>
					<input type="text" name="companynum" id="companynum" onblur="checkCompanyNum()"/>
				</td>
				<td style="width: 200px"><font class="fot3"></font></td>
			</tr>
			<tr>
				<td>密码：</td>
				<td>
					<input type="password" name="upwd" id="upwd" onblur="checkPwd()"/>
				</td>
				<td><font class="fot4" style="width: 200px"></font></td>
			</tr>
			<tr>
				<td>确认密码：</td>
				<td>
					<input type="password" name="urepwd" id="urepwd" onblur="checkUrepwd()"/> 
				</td>
				<td><font class="fot5" style="width: 200px"></font></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><input type="submit"  value="注册" style="color: #FFFFFF"/></td>
			</tr>
			</table>
		</form>
	</center>
</body>
<script type="text/javascript">
$(function() {
});
function checkName() {
	var name = $("#uname").val();
	if (""!= name) {
		$.ajax({
			type : "POST",
			url : "checkname",
			data : "name=" + name,
			dataType : "json",
			success : function(data) {
				if (data.state == "0") {
					$(".fot1").html("用户名可用");
				}else {
					$(".fot1").html("用户名不可用");
				}
			},
			error : function() {
				alert("error");
			}
		});
	}
}
//验证公司名称
function checkCompanyName() {
	var companyname = $("#companyname").val();
	$(".fot2").html("");
	/* var re =/[`~!@#$%^&*_+<>{}\/[\]]/im; */
	var reg = /^[0-9\u4E00-\u9FA5]*$/;
	/* 所有的为汉字的数字 */
	var state = companyname.match(reg);
	if (companyname != "") {
		if (state == null) {
			$(".fot2").html("只能由汉字与数字组成");
		}else {
			$(".fot2").html("");
		}
	}
}
//验证公司编码
function checkCompanyNum(){
	var companynum=$("#companynum").val();
	$(".fot3").html("");
	var reg=/^\d{11}$/
	var state=companynum.match(reg);
	if (companynum != "") {
		if (state == null) {
			$(".fot3").html("只能11位由数字组成");
		}
	}
}
//密码验证
function checkPwd(){
	var pwd=$("#upwd").val();
	$(".fot4").html("");
	var reg=/\w{5,17}$/;
	var state=pwd.match(reg);
	if (pwd != "") {                        
		if (state == null) {
			$(".fot4").html("只能由6~18位字符、数字和下划线组成");
		}
	}
}
//验证两次输入的密码是否一致
function checkUrepwd(){
	var pwd=$("#upwd").val();
	var repwd=$("#urepwd").val();
	$(".fot5").html("");
	if(pwd!=repwd){
		$(".fot5").html("兩次输入的密码不一致");
	}else {
		$(".fot5").html("密码输入正确");
	}
}
$("#form1").submit(function() {
	if ($("#uname").val() == null || $("#uname").val() == "") {
		alert("用户名不能为空");
		return false;
	}
	if ($("#companyname").val() == null || $("#companyname").val() == "") {
		alert("公司名称不能为空");
		return false;
	}
	if ($("#companynum").val() == null || $("#companynum").val() == "") {
		alert("公司编号不能为空");
		return false;
	}
	if ($("#upwd").val() == null || $("#upwd").val() == "") {
		alert("密码不能为空");
		return false;
	}
	if ($("#urepwd").val() == null || $("#urepwd").val() == "") {
		alert("确认密码不能为空");
		return false;
	}
	return true;
});
</script>
</html>